package entity;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Order {
    private static int nextOrderId = 1000;

    private String id;
    private User user;
    private Restaurant restaurant;
    private Map<Dish, Integer> items;
    private String address;
    private String phone;
    private double totalAmount;
    private String status;
    private String orderTime;

    public Order(User user, Restaurant restaurant, Map<Dish, Integer> items, String address, String phone) {
        this.id = "ORD" + nextOrderId++;
        this.user = user;
        this.restaurant = restaurant;
        this.items = new HashMap<>(items);
        this.address = address;
        this.phone = phone;
        this.status = "已下单";
        this.orderTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

        // 计算总价
        this.totalAmount = 0;
        for (Map.Entry<Dish, Integer> entry : items.entrySet()) {
            this.totalAmount += entry.getKey().getPrice() * entry.getValue();
        }
    }

    public String getId() {
        return id;
    }

    public User getUser() {
        return user;
    }

    public Restaurant getRestaurant() {
        return restaurant;
    }

    public Map<Dish, Integer> getItems() {
        return items;
    }

    public String getAddress() {
        return address;
    }

    public String getPhone() {
        return phone;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public String getStatus() {
        return status;
    }

    public String getOrderTime() {
        return orderTime;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
